package com.br.estoque.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.br.estoque.bean.Login;

public class LoginDAO extends DataUtils{
	public List<Login> getAll(){
		List<Login> listaLogin = new ArrayList<Login>();
		Connection conn = null;
		PreparedStatement stmt = null;
		Login login = null;
		ResultSet rs = null;
		try {
			conn = getConnection();
			stmt = conn.prepareStatement("SELECT * FROM login");
			rs = stmt.executeQuery();
			
			while(rs.next()){
				login = new Login();
				login.setId(rs.getInt("id_login"));
				login.setUsuario(rs.getString("usuario"));
				login.setSenha(rs.getString("senha"));
				login.setNome(rs.getString("nome"));
				listaLogin.add(login);
			}
			return listaLogin;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			
			try {
				stmt.close();
				conn.close();
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return listaLogin;
	}
}
